
#include <stdint.h>

#define SCREEN_XSIZE 320
#define SCREEN_YSIZE 480


#if 0

#if 0
#define R61581_HSPL 0  /*HSYNC signal polarity*/
#define R61581_HSL  10 /*HSYNC length (Not Implemented)*/
#define R61581_HFP  10 /*Horitontal Front poarch (Not Implemented)*/
#define R61581_HBP  10 /*Horitontal Back poarch (Not Implemented */
#define R61581_VSPL 0  /*VSYNC signal polarity*/
#define R61581_VSL  10 /*VSYNC length (Not Implemented)*/
#define R61581_VFP  8  /*Vertical Front poarch*/
#define R61581_VBP  8  /*Vertical Back poarch */
#define R61581_DPL  0  /*DCLK signal polarity*/
#define R61581_EPL  1  /*ENABLE signal polarity*/

uint8_t cmd_B0[] = {0xB0, 0x00};
uint8_t cmd_B3[] = {0xB3, 0x02, 0x00, 0x00, 0x10};
uint8_t cmd_B4[] = {0xB4, 0x00};
uint8_t cmd_B9[] = {0xB9, 0x01, 0xFF, 0xFF, 0x18};
uint8_t cmd_C0[] = {0xC0, 0x02, 0x3B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x43};             /*Panel Driving Setting*/
uint8_t cmd_C1[] = {0xC1, 0x08, 0x15, R61581_VFP, R61581_VBP};                         /*Display Timing Setting for Normal Mode */
uint8_t cmd_C4[] = {0xC4, 0x15, 0x03, 0x03, 0x01};                                     /*Source/VCOM/Gate Driving Timing Setting*/
uint8_t cmd_C6[] = {0xC6, 0x00};                                                       /*Interface Setting*/
uint8_t cmd_C8[] = {0xC8, 0x0c, 0x05, 0x0A, 0x6B, 0x04, 0x06, 0x15, 0x10, 0x00, 0x31}; /*Gamma Set*/
uint8_t cmd_0C[] = {0x0C, 0x55};
uint8_t cmd_3A[] = {0x3A, 0x55};
uint8_t cmd_36[] = {0x36, 0x00};
uint8_t cmd_38[] = {0x38};
uint8_t cmd_D0[] = {0xD0, 0x07, 0x07, 0x14, 0xA2};
uint8_t cmd_D1[] = {0xD1, 0x03, 0x5A, 0x10};
uint8_t cmd_D2[] = {0xD2, 0x03, 0x04, 0x04};
// R61581_ORI == 0
// uint8_t cmd_36[] = {0x36, 0xE0};
// uint8_t cmd_36[] = {0x36, 0x20};
#endif


uint8_t cmd_B0[] = {0xB0,0x00};
uint8_t cmd_B3[] = {0xB3,0x02,0x00,0x00,0x00};
uint8_t cmd_B4[] = {0xB4,0x00};
uint8_t cmd_C0[] = {0xC0,0x13,0x3B,0x00,0x03,0x00,0x01,0x00,0x43}; // Diving
uint8_t cmd_C1[] = {0xC1,0x08,0x12,0x08,0x08}; /*Display Timing Setting for Normal Mode */
uint8_t cmd_C4[] = {0xC4,0x11,0x07,0x03,0x03}; /*Source/VCOM/Gate Driving Timing Setting*/
uint8_t cmd_C6[] = {0xC6, 0x00};
uint8_t cmd_C8[] = {0xC8,0x04,0x09,0x16,0x5A,0x02,0x0A,0x16,0x05,0x00,0x32,0x05,0x16,0x0A,0x53,0x08,0x16,0x09,0x04,0x32,0x00}; /*Gamma Set*/
uint8_t cmd_36[] = {0x36, 0x00}; // 0E  20
uint8_t cmd_0C[] = {0x0C,0x55};
uint8_t cmd_3A[] = {0x3A,0x55};
uint8_t cmd_38[] = {0x38};
uint8_t cmd_D0[] = {0xD0,0x07,0x07,0x1E,0x03};
uint8_t cmd_D1[] = {0xD1,0x03,0x52,0x10};
uint8_t cmd_D2[] = {0xD2,0x03,0x24,0x04};

#else

uint8_t cmd_B0[] = {0xB0, 0x00};
uint8_t cmd_B3[] = {0xB3, 0x02, 0x00, 0x00, 0x00};
uint8_t cmd_C0[] = {0xC0, 0x13, 0x3B, 0x00, 0x02, 0x00, 0x01, 0x00, 0x43};
// uint8_t cmd_C0[] = {0xC0, 0x16, 0x3B, 0x00, 0x02, 0x00, 0x01, 0x00, 0x43};
// uint8_t cmd_C1[] = {0xC1, 0x08, 0x16, 0x08, 0x08};
uint8_t cmd_C1[] = {0xC1, 0x08, 0x1F, 0x08, 0x08};
uint8_t cmd_C4[] = {0xC4, 0x11, 0x07, 0x03, 0x03};
uint8_t cmd_C6[] = {0xC6, 0x00};
uint8_t cmd_C8[] = {0xC8, 0x03, 0x03, 0x13, 0x5C, 0x03, 0x07, 0x14, 0x08, 0x00, 0x21, 0x08, 0x14, 0x07, 0x53, 0x0C, 0x13, 0x03, 0x03, 0x21, 0x00};
uint8_t cmd_0C[] = {0x0C, 0x55};
uint8_t cmd_36[] = {0x36, 0x00};
uint8_t cmd_38[] = {0x38};
uint8_t cmd_3A[] = {0x3A, 0x55};
// uint8_t cmd_D0[] = {0xD0, 0x07, 0x02, 0x1D, 0x03};
// uint8_t cmd_D1[] = {0xD1, 0x03, 0x4A, 0x10};
// uint8_t cmd_D2[] = {0xD2, 0x03, 0x14, 0x04};

uint8_t cmd_D0[] = {0xD0, 0x07, 0x02, 0x15, 0x03};
uint8_t cmd_D1[] = {0xD1, 0x03, 0x30, 0x10};
uint8_t cmd_D2[] = {0xD2, 0x03, 0x14, 0x04};

#endif

uint8_t cmd_11[] = {0x11};
// sleep_ms(10};
uint8_t cmd_2A[] = {0x2A, 0x00, 0x00, ((SCREEN_XSIZE - 1) >> 8) & 0XFF, (SCREEN_XSIZE - 1) & 0XFF};
uint8_t cmd_2B[] = {0x2B, 0x00, 0x00, ((SCREEN_YSIZE - 1) >> 8) & 0XFF, (SCREEN_YSIZE - 1) & 0XFF};
// sleep_ms(10};
uint8_t cmd_29[] = {0x29};
// sleep_ms(5};
uint8_t cmd_2C[] = {0x2C};
// sleep_ms(5};